/*******************************************************************************
 * NEW Question FORM
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * A local select box propose a choice between available locales
 */
qx.Class.define("bip.ui.form.LocalSelectBox",
{
  extend : qx.ui.form.SelectBox,
  
  construct : function()
  {
    this.base(arguments);
    this.__items = {};
    this.__items["en"] = new qx.ui.form.ListItem("en", "bip/flags/en.png","en");
    this.add(this.__items["en"]);
    this.__items["fr"] = new qx.ui.form.ListItem("fr", "bip/flags/fr.png","fr");
    this.add( this.__items["fr"] );
    var currentLocale = qx.locale.Manager.getInstance().getLocale();
    if (this.__items[currentLocale] != null) {
    	this.setSelection([this.__items[currentLocale]]);
    } else {
    	this.setSelection([this.__items["en"]]);
    	qx.locale.Manager.getInstance().setLocale("en");
    }
    this.addListener("changeSelection",function(evt) {
    	var selection = evt.getData();
    	if (selection.length > 0) {
    		var item = selection[0];
    		qx.locale.Manager.getInstance().setLocale(item.getModel());
    	}
    },this); 
   
  },
  
  properties :
  {
    appearance :
    {
      refine : true,
      init : "locallist"
    }
  },
  
	/*
	 *****************************************************************************
    MEMBERS
	 *****************************************************************************
	 */

 	members :
 	{
 		__items: null
 		
 	},
 	
	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this.__items = null;
		this._disposeObjects();
	}

  
});